package com.k.ums.context;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @Description:
 * @Author: kt
 * @CreateTime: 2022/1/8
 */

@Component
public final class UmsContextRegistry implements BeanFactoryPostProcessor, ApplicationContextAware, InitializingBean {

    private UmsContext umsContext;

    public UmsContextRegistry() {
        umsContext = new UmsContext();
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        umsContext.setDelegator(applicationContext);
    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        umsContext.setBeanFactory(beanFactory);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        Ums.setUmsContext(umsContext);
    }
}
